﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TGB.Core.Infrastructure;
using TGBTech.Core.Models.Services;

namespace TGBTech.WebAdmin.Controllers
{
    public class SoNhatKyChungController : Controller
    {
        private TGBTechDb db = new TGBTechDb();
        //
        // GET: /SoNhatKyChung/
        public ActionResult Index()
        {

            return View(db.SoNhatKyChung.ToList());
        }

        //
        // GET: /SoNhatKyChung/Details/5
        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /SoNhatKyChung/Create
        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /SoNhatKyChung/Create
        [HttpPost]
        public ActionResult Create(DateTime? StartDate, DateTime? EndDate)
        {
            try
            {
                // TODO: Add insert logic here
                if(StartDate.HasValue == true && EndDate.HasValue == true)
                {
                    //Goi services
                    SoNhatKyChungService service = new SoNhatKyChungService();
                    var SoNhatKyChung = service.createSoNhatKyChung(StartDate.GetValueOrDefault(), EndDate.GetValueOrDefault());
                    ViewBag.SoNhatKyChung = SoNhatKyChung;
                    var list = SoNhatKyChung.ListNhatKyChung;
                    return View("Create", list);
                }
               
                return View();
            }
            catch
            {
                return View();
            }
        }


        [HttpPost]
        public ActionResult Save(DateTime? Date)
        {
            // Save here

            return RedirectToAction("Index");
        }


        //
        // GET: /SoNhatKyChung/Delete/5
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /SoNhatKyChung/Delete/5
        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
